//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

/* depend.h */

#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __DEPEND_H__
#define __DEPEND_H__

#include <stdlib.h>

typedef struct  _tagFILETIME
{
    UInt32 dwLowDateTime;
    UInt32 dwHighDateTime;
} FILETIME, *PFILETIME;

typedef union _ULARGE_INTEGER
{
    struct {
        UInt32 LowPart;
        UInt32 HighPart;
    } u;
    UInt64 QuadPart;
} ULARGE_INTEGER, *PULARGE_INTEGER;

#undef IN
#define IN

#undef OUT
#define OUT

#define IO_INVALID_HANDLE_VALUE ((PVoid)-1L)
#define IO_ErrorToECODE

// FILE ATTRIBUTE
#define IO_FA_READONLY                 0x00000001
#define IO_FA_NORMAL                   0x00000080
#define IO_FA_DIRECTORY                0x00000010
#define IO_CREATE_ALWAYS               2
#define IO_OPEN_ALWAYS                 4
#define IO_MAXIMUM_ALLOWED             0x2000000
#define IO_GENERIC_READ                0x80000000
#define IO_GENERIC_WRITE               0x40000000
#define IO_GENERIC_EXECUTE             0x20000000
#define IO_GENERIC_ALL                 0x10000000

#define IO_INVALID_FILE_SIZE ((UInt32)0xFFFFFFFF)
#define IO_INVALID_SET_FILE_POINTER ((UInt32)-1)
#define IO_INVALID_FILE_ATTRIBUTES ((UInt32)-1)

// FILE SHARE
#define IO_FS_READ        0x00000001
#define IO_FS_WRITE       0x00000002
#define IO_FS_DELETE      0x00000004
#define IO_FS_VALID_FLAGS 0x00000007

#define IO_INVALID_SET_FILE_POINTER ((UInt32)-1)

#define IO_FILE_BEGIN                   0
#define IO_FILE_CURRENT                 1
#define IO_FILE_END                     2

/*
 * from 'unistd.h'
 */
#define IO_SEEK_SET              0
#define IO_SEEK_CUR              1
#define IO_SEEK_END              2

typedef struct _IO_FIND_DATA
{
    UInt32 ulFileAttributes;
    FILETIME ftCreationTime;
    FILETIME ftLastAccessTime;
    FILETIME ftLastWriteTime;
    UInt32 ulFileSizeHigh;
    UInt32 ulFileSizeLow;
    UInt32 ulReserved0;
    UInt32 ulReserved1;
    WChar cFileName[_MAX_PATH];
    WChar cAlternateFileName[14];
} IO_FIND_DATA
, *PIO_FIND_DATA
, *LPIO_FIND_DATA;

UInt32 IO_GetFileAttributes (
                IN WString pFileName);

Boolean IO_SetFileAttributes (
                IN WString pFileName,
                IN UInt32 fileAttributes);

Boolean IO_DeleteFile (
                IN WString pFileName);

Boolean IO_MoveFile (
                IN WString pExistingFileName,
                IN WString pNewFileName);

Boolean IO_CreateDirectory (
                IN WString pPathName);

Boolean IO_RemoveDirectory (
                IN WString pPathName);

PVoid IO_FindFirstFile (
                IN WString pFileName,
                OUT PIO_FIND_DATA pFindFileData);

Boolean IO_FindNextFile(
                IN PVoid hFindFile,
                OUT PIO_FIND_DATA pFindFileData);

PVoid IO_CreateFile(
                IN WString pFileName,
                IN UInt32 desiredAccess,
                IN UInt32 shareMode,
                IN UInt32 creationDisposition,
                IN UInt32 flagsAndAttributes,
                IN PVoid hTemplateFile);

Boolean IO_GetFileTime (
                IN PVoid hFile,
                OUT PFILETIME pCreationTime,
                OUT PFILETIME pLastAccessTime,
                OUT PFILETIME pLastWriteTime);

Boolean IO_ReadFile (
                IN PVoid hFile,
                OUT Void* pBuffer,
                IN UInt32 nNumberOfBytesToRead,
                OUT UInt32* pNumberOfBytesRead);

UInt32 IO_SetFilePointer (
                IN PVoid hFile,
                IN OUT Int32 lDistanceToMove,
                IN Int32* pDistanceToMoveHigh,
                IN UInt32 ulMoveMethod);

Boolean IO_WriteFile (
                IN PVoid hFile,
                IN const PVoid pBuffer,
                IN UInt32 nNumberOfBytesToWrite,
                OUT UInt32* pNumberOfBytesWritten);

UInt32 IO_GetFileSize (
                IN PVoid hFile,
                OUT UInt32* lpFileSizeHigh);

Boolean IO_SetEndOfFile (
                IN PVoid hFile);

Boolean IO_FindClose (
                IN PVoid hFindFile);

Boolean IO_GetDiskFreeSpace (
                IN WString pDirectoryName,
                OUT PULARGE_INTEGER pFreeBytesAvailable,
                OUT PULARGE_INTEGER pTotalNumberOfBytes,
                OUT PULARGE_INTEGER pTotalNumberOfFreeBytes);

Boolean IO_CloseHandle(
                IN PVoid hFile);

#endif //__DEPEND_H__
